#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=50005;
int n,l,f=1,r=1;
int q[N];
ll sumL[N],dp[N],g[N];
int main(){
	scanf("%d%d",&n,&l);++l;
	for(int i=1;i<=n;++i){
		scanf("%lld",sumL+i);
		sumL[i]+=sumL[i-1];
	}
	for(int i=1;i<=n;++i)dp[i]=1125899906842624;
	for(int i=1;i<=n;++i)sumL[i]+=i;
	for(int i=1;i<=n;++i){
		while(f<r&&g[q[f+1]]-g[q[f]]<=2*(sumL[i]-l)*(sumL[q[f+1]]-sumL[q[f]]))++f;
		dp[i]=dp[q[f]]+(sumL[i]-l-sumL[q[f]])*(sumL[i]-l-sumL[q[f]]);g[i]=dp[i]+sumL[i]*sumL[i];
		while(f<r&&(g[q[r]]-g[q[r-1]])*(sumL[i]-sumL[q[r]])>=(g[i]-g[q[r]])*(sumL[q[r]]-sumL[q[r-1]]))--r;
		q[++r]=i;
	}
	printf("%lld",dp[n]);
	return 0;
}
